home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS etc.cpt / Module Source / E-mail / EnterEmail.c < prev    next >
Text File  |  1991-11-22  |  10KB  |  372 lines

  1. /* *********************************************************************************
  2.      
  3.       MODULE:        EnterEmail Module
  4.       
  5.      DESCRIPTION:    This EnterEmail Module is a simple module for MUBBS, the
  6.                      Multi-User Bulliten Board System Software.
  7.                      
  8.      AUTHOR:        Noam Freedman
  9.      
  10.      Copyright © 1990 by Noam Freedman. Portions are also Copyright Symantec Corp.
  11.  
  12.      This program source code and it's compiled version IS NOT IN THE
  13.      PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NMF" file for details
  14.      regarding use of this program source code and it's compiled version.
  15.      
  16.      Revision History:
  17.      ============================================================
  18.       8/26/91 - Started programming
  19.      11/ 4/91 - Edited for release
  20.      ============================================================
  21.      
  22.  
  23.     ******************************************************************************** */
  24.  
  25.  
  26. #define        INMAIN
  27.  
  28. #include    "MUBBS Module.h"
  29. #include    "Email.h"
  30. #include    <SetUpA4.h>
  31.  
  32. /* my globals for this module */
  33.  
  34. pascal void main (mode1,G1,P1)
  35.        int mode1;
  36.        struct GS *G1;
  37.        Ptr P1;
  38. {
  39. Handle temph;
  40. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  41. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  42. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  43.  
  44. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  45. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  46.  
  47. switch (mode[u]) { /* any un-handled modes return error from this module */
  48.     case 3:
  49.         if (getinfo(P1) != 0){ /* mode 3 because we are passing a user pointer */
  50.             G->moduleresult=0; /* mode 2 doesnt work here, we need a pointer */
  51.             break;
  52.             }
  53.         enteremail(P1);
  54.         G->moduleresult=0;
  55.         break;
  56.     case 98:
  57.         versionck(version); /* just return after this call, don't modify anything */
  58.         break;        
  59.     case 0:
  60.         strcpy (G->programmer,"Noam Freedman"); /* show the programmer's name up to 20 chars*/
  61.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  62.         break;
  63.     default:
  64.         G->moduleresult=1; /* return bad code */
  65.     };
  66.  
  67. HUnlock(temph); /* unlocks this module, do this ! */
  68. RestoreA4(); /* call this when you are all done */
  69. }
  70.  
  71.  
  72. getinfo(S)
  73. struct EnterStruct *S;
  74. {
  75. char pad[100]; /* this is a fix for a problem */
  76. int num;
  77. char temp[40];
  78.  
  79.  
  80. if (!G->online[u]) { return(2); } /* do this check so we can log out if hang up */
  81.  
  82. strcpy(S->FromUser,G->username[u]);
  83.  
  84. if(S->ToUser[0] != 0) goto skipit; /* if users to name isn't blank */
  85.  
  86. enterit:
  87. send("]]]");
  88. send("Enter the user's name (or \"Sysop\") : ");
  89. portsin(S->ToUser, 33);
  90. send(G->CR[u]);
  91.  
  92. if (S->ToUser[0] == 0)
  93.     {
  94.     send("]]Message Aborted.]");
  95.     S->result = 1;
  96.     return(1);
  97.     }
  98.  
  99. strcpy(temp,S->ToUser);
  100. strtoupper(temp);
  101. if(strcmp(temp,"SYSOP") == 0) {
  102.     strcpy (S->ToUser,G->sysopname); /* get the sysop's name */
  103.     goto skipit;
  104.     }
  105.  
  106. if ( ! getuserinfo(S->ToUser)) { /* see if this user exists */
  107.     send ("]There is no such user as \"%s\" on this system, please try again.]",S->ToUser);
  108.     goto enterit;
  109.     }
  110.  
  111. skipit:
  112. if (S->ToUser[0] != 0)
  113.     {
  114.     send("]]Emailing \"%s\"",S->ToUser);
  115.     send("]]Title: ");        
  116.     portsin(S->title, 69);
  117.     if (S->title[0] != 0)
  118.         {
  119.         S->result = 0;
  120.         return(0);
  121.         }
  122.     else
  123.         {
  124.         send("]]Message Aborted.]");
  125.         S->result = 1;
  126.         return(1);
  127.         }
  128.     }
  129. else
  130.     {
  131.     send("]]Message Aborted.]");
  132.     S->result = 1;
  133.     return(1);
  134.     }
  135. }
  136.  
  137. enteremail(S)
  138. struct EnterStruct *S;
  139. {
  140. char pad[100]; /* this is a fix for a problem */
  141. char ch;
  142. int a = 0,      /* flag */
  143.     i = 0,        /* temp # holder */
  144.     tf = FALSE,    /* true/false flag */
  145.     num;            /* true/false flag when calling functions */
  146. S->numlines = 0; /* num lines */
  147.     
  148. send("]]A line can contain 75 characters, max 50 lines.]");
  149. send("To end or edit, enter a carriage return on an empty line.]");
  150. send("    ---------1---------2---------3---------4---------5---------6---------7----!]");
  151.  
  152. G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  153. if( (S->numlines+1) < 9 )
  154.     send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  155. else                    
  156.     send("%i: ",(S->numlines+1)); /* don't check for anything here */
  157. G->nocheck[u]=FALSE; /* turn it back on */
  158.     
  159. while ( a == 0 )
  160.     {
  161.     if (!G->in()) {num = 2;goto byebye;} /* carrier detect or time out ? */
  162.     ch = G->input[u];
  163.     if ( ch == 13)
  164.         {                                
  165.         G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  166.         send(G->CR[u]); /* don't check for anything here */
  167.         G->nocheck[u]=FALSE; /* turn it back on */
  168.         if (S->numlines >= 49) i = 0;
  169.         else S->numlines = S->numlines + 1;
  170.             
  171.         if (i == 0)
  172.             {
  173.             if(S->numlines <= 48) S->numlines = S->numlines - 2;
  174.             num = askline(S);
  175.             if (num != 0)  goto byebye;
  176.             }
  177.         i = 0;
  178.         S->emailtext[S->numlines][i]= '\0'; 
  179.         G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  180.         if( (S->numlines+1) <= 9 )
  181.             send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  182.         else
  183.             send("%i: ",(S->numlines+1)); /* don't check for anything here */
  184.         G->nocheck[u]=FALSE; /* turn it back on */
  185.         }
  186.     else 
  187.         if ( ch == 8 ) /* handle backspace */
  188.             {
  189.             if (i>0) {
  190.                 G->serout('\b');
  191.                 G->serout(' ');
  192.                 G->serout('\b');
  193.                 i = i - 1;
  194.                 S->emailtext[S->numlines][i] = '\0';
  195.                 }
  196.             if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  197.             }
  198.     else
  199.         if ( i >= 74 )
  200.             {
  201.             G->serout(ch); /* doesn't check for "S" or "C" */
  202.             if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  203.             i = 0;
  204.             if (S->numlines >= 49) continue;
  205.             S->numlines = S->numlines + 1;
  206.             S->emailtext[S->numlines][i] = ch;
  207.             S->emailtext[S->numlines][i+1] = '\0';
  208.             G->nocheck[u]=TRUE; /* no control checking on ouput ! */
  209.             send(G->CR[u]);
  210.             if( (S->numlines+1) <= 9 )
  211.                 send(" %i: ",(S->numlines+1)); /* don't check for anything here */
  212.             else
  213.                 send("%i: ",(S->numlines+1)); /* don't check for anything here */
  214.             G->nocheck[u]=FALSE; /* turn it back on */
  215.             }
  216.     else
  217.         {
  218.         G->serout(ch); /* doesn't check for "S" or "C" */
  219.         if (!G->online[u]) {num = 2;goto byebye;} /* time out ? */
  220.         S->emailtext[S->numlines][i] = ch;
  221.         S->emailtext[S->numlines][i+1] = '\0';
  222.         i=i+1;
  223.         }
  224.     }
  225. byebye:
  226. S->result = num;
  227. }
  228.  
  229.  
  230. askline(S)
  231. struct EnterStruct *S;
  232. {
  233. char pad[100]; /* this is a fix for a problem */
  234. char tempstring[255], ch;
  235. int num = 0,  /* flag */
  236.     b = 0,  /* flag */
  237.     c = 0,  /* temp variable */
  238.     d = 0;  /* temp variable */
  239.  
  240. while ( b == 0 )
  241.     {                                            
  242.     if (S->numlines == 0 && S->emailtext[0][0] == '\0') /* if no text at all */
  243.         {
  244.         send("]Message Cancelled.]");
  245.         num = 1;
  246.         b = 1;
  247.         break;
  248.         }
  249.     if (!(cmd1("]]>> Continue, Delete line, Edit line, List, Save, Quit : ")))
  250.         {
  251.         G->online[u]=FALSE;
  252.         b = 1;
  253.         num = 2;
  254.         }
  255.     send(G->CR[u]);
  256.     ch = G->input[u];
  257.     switch (ch)
  258.         {
  259.         case 'C':
  260.                 if ( S->numlines <=48 )
  261.                     {
  262.                     S->numlines = S->numlines + 1;
  263.                     num = 0;
  264.                     b = 1;
  265.                     }
  266.                 else
  267.                     send("]Message is already 50 lines!]");
  268.                 break;
  269.         case 'D':
  270.                 send("]Enter line number to delete, or RETURN to exit : ");
  271.                 portsin(tempstring,3);
  272.                 send(G->CR[u]);
  273.                 c = strtoint(tempstring);
  274.                 if (c <= 0) break;
  275.                 if (c > (S->numlines + 1)){
  276.                     send("]]There is no such line number.]]");
  277.                     break;
  278.                     }
  279.                 send("]Line #%d reads:]",c);
  280.                 send(S->emailtext[(c-1)]);
  281.                 cmd1("]]Are you sure you want to DELETE it (Y/N)? ");
  282.                 ch = G->input[u];
  283.                 send(G->CR[u]);
  284.                 if (ch=='Y'){
  285.                     for (d = (c-1); d <S->numlines; d++)
  286.                         strcpy(S->emailtext[d],S->emailtext[d+1]);
  287.                     S->numlines = S->numlines - 1;
  288.                     }
  289.                 else
  290.                     {
  291.                     send("]Line was not deleted.]");
  292.                     }
  293.                 break;
  294.         case 'E':
  295.                 send("]]The edit-line option for the program has been unwritten as of yet.]");
  296.                 break;
  297.         case 'S':
  298.                 if(S->numlines >49) S->numlines=49; /* just to make sure */
  299.                 num = 10;
  300.                 b = 1;
  301.                 break;
  302.         case 'L':
  303.                 for (d = 0;d<=S->numlines && d<=49;d++)
  304.                     {
  305.                     if( (S->numlines+1) < 9 )
  306.                         send(" %i: %s]",(d+1),S->emailtext[d]);            
  307.                     else                    
  308.                         send("%i: %s]",(d+1),S->emailtext[d]);
  309.                     if (G->cancel[u]) break; /* did they press cancel? */
  310.                     }
  311.                 send(G->CR[u]);
  312.                 break;
  313.         case 'Q':
  314.                 cmd1("]Are you sure you want to quit (Y/N)? ");
  315.                 ch = G->input[u];
  316.                 send(G->CR[u]);
  317.                 if (ch=='Y')
  318.                     {
  319.                     send("]Message Cancelled.]");
  320.                     num = 1;
  321.                     b = 1;
  322.                     }
  323.                 break;
  324.         }
  325.                     
  326.     }
  327. return(num);
  328. }
  329.  
  330. getuserinfo(gettemp) /* stolen from the "login" module code */
  331. char *gettemp;
  332. {
  333. char tempname[maxnamelength];
  334. char temp1[maxnamelength],temp2[maxnamelength];
  335. char tchar[258];
  336. int count;
  337. long pos;
  338. FILE *stream;
  339.  
  340. if ((stream = fopen(":user:userlist", "r")) == NULL) {
  341.     print("C> FILE ERROR - cannot open :bbsuser:userlist\n");
  342.     send("]FILE ERROR - Can't open the user list file !]");
  343.     return FALSE;
  344.     }
  345. count = 0;
  346. pos=0;
  347. sprintf(temp2,"%-30s",gettemp); /* Prepare the user name for compare */
  348. strtoupper(temp2);
  349.  
  350. while (TRUE){
  351.  
  352.     if(fseek(stream,pos,0) != 0) print("C> Fseek failed\n"); /* go to the record */
  353.     fgets(tchar,33,stream); if (feof(stream)) goto goteof; sscanf(tchar,"%32[^~]",tempname); /* the user's name */
  354.     strcpy(temp1,tempname); /* save the actual name for later */
  355.     strtoupper(tempname);
  356.     if (strcmp(tempname,temp2) == 0) {
  357.         removespaces(temp1); /* takes out trailing spaces */
  358.         strcpy(gettemp,temp1); /* make their name correct */
  359.         fclose(stream);
  360.         return TRUE;
  361.         }
  362.     otheruser(FALSE); /* do switch */
  363.     if ((++count % 10) == 0) {sendnc (".");} /* show dots */
  364.     pos=pos+801; /* move up a record */
  365.     }
  366. goteof:
  367. fclose(stream);
  368. return FALSE;  /* user was not found */
  369.  
  370. }
  371.  
  372.